######### Tables in main text ########

###### Table 1 base line  ########## 

attach(cabinet_filter_data)
set.seed(1234567)

base.mod.1<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_12m,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(base.mod.1)
LMtest.base.mod.1<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_12m,
                               data = cabinet_filter_pdata, model="random"))$p.value


base.mod.2<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_6m,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(base.mod.2)
LMtest.base.mod.2<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_6m,
                               data = cabinet_filter_pdata, model="random"))$p.value


base.mod.3<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_3m,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(base.mod.3)
LMtest.base.mod.3<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_3m,
                               data = cabinet_filter_pdata, model="random"))$p.value


base.mod.4<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_12m 
  + d.unemployment+ retail+ imf+protest_freq,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(base.mod.4)
LMtest.base.mod.4<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_12m 
                               + d.unemployment+ retail+ imf+protest_freq,
                               data = cabinet_filter_pdata, model="random"))$p.value


base.mod.5<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_6m
  + d.unemployment+ retail+ imf+protest_freq,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(base.mod.5)
LMtest.base.mod.5<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_6m
                               + d.unemployment+ retail+ imf+protest_freq,
                               data = cabinet_filter_pdata, model="random"))$p.value


base.mod.6<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_3m
  + d.unemployment+ retail+ imf+protest_freq,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(base.mod.6)
LMtest.base.mod.6<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_3m
                               + d.unemployment+ retail+ imf+protest_freq,
                               data = cabinet_filter_pdata, model="random"))$p.value


htmlreg(list(base.mod.1,
             base.mod.2,
             base.mod.3,
             base.mod.4,
             base.mod.5,
             base.mod.6),file = "Table1.doc",digits = 3,stars = c(0.001, 0.01, 0.05, 0.1),caption.above = T,
        reorder.coef=c(2,3,4,5,6,7,8,9,1))

as.data.frame(rbind(LMtest.base.mod.1,
                    LMtest.base.mod.2,
                    LMtest.base.mod.3,
                    LMtest.base.mod.4,
                    LMtest.base.mod.5,
                    LMtest.base.mod.6))

###### Table 2 Interactions  ########## 

attach(cabinet_filter_data)
set.seed(1234567)

int.mod.2<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_6m
  + d.unemployment+ retail+ imf+protest_freq+austerity_6m*d.unemployment,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(int.mod.2)
LMtest.int.mod.2<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_6m
                              + d.unemployment+ retail+ imf+protest_freq+austerity_6m*d.unemployment,
                              data = cabinet_filter_pdata, model="random"))$p.value


int.mod.5<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_6m
  + d.unemployment+ retail+ imf+protest_freq+austerity_6m*imf,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(int.mod.5)
LMtest.int.mod.5<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_6m
                              + d.unemployment+ retail+ imf+protest_freq+austerity_6m*imf,
                              data = cabinet_filter_pdata, model="random"))$p.value


int.mod.8<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_6m
  + d.unemployment+ retail+ imf+protest_freq+austerity_6m*protest_freq,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(int.mod.8)
LMtest.int.mod.8<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_6m
                              + d.unemployment+ retail+ imf+protest_freq+austerity_6m*protest_freq,
                              data = cabinet_filter_pdata, model="random"))$p.value


int.mod.11<- lme(
  fixed = vicab_filtered ~ l.vicab_filtered+austerity_6m
  + d.unemployment+ retail+ imf+protest_freq
  +austerity_6m*d.unemployment++austerity_6m*imf++austerity_6m*protest_freq,
  random = ~ 1+l.vicab_filtered | country, control = lmeControl(opt = 'optim'))
summary(int.mod.11)
LMtest.int.mod.11<-pdwtest(plm(vicab_filtered ~ l.vicab_filtered+austerity_6m
                               + d.unemployment+ retail+ imf+protest_freq
                               +austerity_6m*d.unemployment++austerity_6m*imf++austerity_6m*protest_freq,
                               data = cabinet_filter_pdata, model="random"))$p.value


htmlreg(list(int.mod.2,
             int.mod.5,
             int.mod.8,
             int.mod.11),file = "Table2.doc",digits = 3,stars = c(0.001, 0.01, 0.05, 0.1),caption.above = T,
        reorder.coef=c(2,3,9,11,4,5,6,7,8,10,1))

as.data.frame(rbind(LMtest.int.mod.2,
                    LMtest.int.mod.5,
                    LMtest.int.mod.8,
                    LMtest.int.mod.11))



###### Table 3 Greece ########## 


greece1 <- dynlm(voteintention_cabinet~L(voteintention_cabinet,1) 
                 + first_bailout,data=greece)
summary(greece1)
adl.1.res <- greece1$residuals
Box.test(adl.1.res,30,"Ljung")


greece2 <- dynlm(voteintention_cabinet~L(voteintention_cabinet,1) 
                 + mid_term,data=greece)
summary(greece2)
adl.2.res <- greece2$residuals
Box.test(adl.2.res,30,"Ljung")


greece3 <- dynlm(voteintention_cabinet~L(voteintention_cabinet,1) 
                 + second_bailout,data=greece)
summary(greece3)
adl.3.res <- greece3$residuals
Box.test(adl.3.res,30,"Ljung")


greece4 <- dynlm(voteintention_cabinet~L(voteintention_cabinet,1) 
                 + third_bailout,data=greece)
summary(greece4)
adl.4.res <- greece4$residuals
Box.test(adl.4.res,30,"Ljung")


greece5 <- dynlm(voteintention_cabinet~L(voteintention_cabinet,1) 
                 + austerity_6m,data=greece)
summary(greece5)
adl.5.res <- greece5$residuals
Box.test(adl.5.res,30,"Ljung")

htmlreg(list(
  greece1,
  greece2,
  greece3,
  greece4,
  greece5),
  file = "Table3.doc",digits = 3,stars = c(0.001, 0.01, 0.05, 0.1),caption.above = T,
  reorder.coef=c(2,3,4,5,6,7,1))